/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package rothserve;
import java.io.*;
import java.io.InputStreamReader;
import java.net.*;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
/**
 *
 * @author Alex
 */
public class jpg {
    PrintWriter writer2;
        public void jpgWrite(String newPath, PrintWriter writer, Socket client){
            try{
                System.out.println("JPEG Image");
                writer2=writer;
		BufferedImage imageBrow = ImageIO.read(new File(newPath));

		writer.println("HTTP/1.1 200 OK");
		writer.println("Content-Type: image/gif");
		writer.println("");
		ImageIO.write(imageBrow, "jpg", client.getOutputStream());
		System.out.println("JPEG Image Written");
                }catch(FileNotFoundException e){
                typeErrorHTTPFNF();
                }

                catch(Exception ex) {
                typeErrorHTTPGSE();
                }

}
        public void typeErrorHTTPFNF() {
        writer2.println("HTTP/1.1 404 Not Found");
        writer2.println("");
writer2.println("<html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL was not found on this server.</p><hr><address>RothServe/0.01 Mac Server</address></body></html>");
writer2.close();
System.out.println("404Sent");
}

public void typeErrorHTTPGSE() {
writer2.println("HTTP/1.1 500 Internal Server Error");
writer2.println("");
writer2.println("<html><head><title>500 Internal Server Error</title></head><body><h1>Not Found</h1><p>There is an internal problem with this server, check back later.</p><hr><address>RothServe/0.01 Mac Server</address></body></html>");
writer2.close();
System.out.println("500Sent");
}
}
